#include <iostream>
#include "bpNet.h"
////////////////////////////////////////////////////
//  demo: xor teisingumo lenteles apmokymas 
//
//            naudojant DSP klase
////////////////////////////////////////////////////
using namespace std;
int main()
{
  int   i;
  bpNet Network;
  float **data, *output;
  float **targets;
  
  
  data = (float **)calloc(4,sizeof(float *));
  targets = (float **)calloc(4,sizeof(float*));
      
       for (i = 0; i < 4; i++)
        {
                data[i] = (float *)calloc(2,sizeof(float));                       
                targets[i] = (float *)calloc(1,sizeof(float));

        }     
 data[0][0] = 0;
 data[0][1] = 0;
 data[1][0] = 0;
 data[1][1] = 1;
 data[2][0] = 1;
 data[2][1] = 0;
 data[3][0] = 1;
 data[3][1] = 1;
 targets[0][0] = 0;
 targets[1][0] = 1;
 targets[2][0] = 1;
 targets[3][0] = 0; 
  

  /*
	int neurons[] = {2,2,1};
  Network.init(neurons,3);
  Network.RandomWeights();  

 if (Network.BpTrain(data,targets,4,100000,0.01) == 1)    
  cout << "pavyko" << endl;
 else cout << "nepavyko" << endl; 
   Network.Save("network.txt");
 */
 
 
  Network.Load("network.txt");  
  output = (float *)calloc(1,sizeof(float));
  for (i = 0; i < 4; i++)
  {
    memset(output,0,sizeof(output));    
    output = Network.getOutput(data[i]);  
    cout << data[i][0] << " xor " << data[i][1] << " = " << output[0] <<  endl;
  }    
 system("pause");
}

